/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormaPagamentoGUI.java
 *
 * Created on 23/07/2011, 16:24:33
 */

package carrancao.gui;

import carrancao.controlador.Fachada;
import carrancao.entidades.FormaPagamento;
import carrancao.exception.CadastrarFormaPagamentoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Lubnnia
 */
public class AlterarFormaPagamentoGUI extends javax.swing.JFrame {

    /** Creates new form FormaPagamentoGUI */
    public AlterarFormaPagamentoGUI() {
        initComponents();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelFormaPagamento = new javax.swing.JLabel();
        jTextFieldFormaPagamento = new javax.swing.JTextField();
        jButtonFechar = new javax.swing.JButton();
        jButtonAlterar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Alterar Forma de Pagamento");

        jLabelFormaPagamento.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabelFormaPagamento.setText("Forma de Pagamento");

        jTextFieldFormaPagamento.setFont(new java.awt.Font("Tahoma", 0, 12));

        jButtonFechar.setFont(new java.awt.Font("Tahoma", 0, 14));
        jButtonFechar.setText("Fechar");
        jButtonFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFecharActionPerformed(evt);
            }
        });

        jButtonAlterar.setFont(new java.awt.Font("Tahoma", 0, 14));
        jButtonAlterar.setText("Alterar");
        jButtonAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAlterarActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setText("Excluir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelFormaPagamento)
                            .addComponent(jTextFieldFormaPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jButtonFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(34, 34, 34)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(66, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelFormaPagamento)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldFormaPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
                    .addComponent(jButtonFechar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
                    .addComponent(jButtonAlterar, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE))
                .addGap(53, 53, 53))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFecharActionPerformed
        dispose();
    }//GEN-LAST:event_jButtonFecharActionPerformed

    private void jButtonAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAlterarActionPerformed
        try {
            if(jTextFieldFormaPagamento.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Caro usuário favor preencher todos os campos obrigatórios!",
                                "Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            } else {

                formaPagamento.setFormaPagamento(jTextFieldFormaPagamento.getText().toUpperCase());
                
                Fachada.getInstance().getFormaControl().alterarFormaPagamento(formaPagamento);
                JOptionPane.showMessageDialog(null, "Dados alterados com sucesso!", "Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
                dispose();
            }
        } catch (CadastrarFormaPagamentoException ex) {
            Logger.getLogger(FormaPagamentoGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButtonAlterarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        if (JOptionPane.showConfirmDialog(null, "Tem certeza que deseja excluir esse usuário?",
                        "Mensagem do Sistema", JOptionPane.YES_NO_OPTION)  == (JOptionPane.YES_OPTION)){

            Fachada.getInstance().getFormaControl().deletarFormaPagamento(formaPagamento);
            dispose();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormaPagamentoGUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonAlterar;
    private javax.swing.JButton jButtonFechar;
    private javax.swing.JLabel jLabelFormaPagamento;
    private javax.swing.JTextField jTextFieldFormaPagamento;
    // End of variables declaration//GEN-END:variables

    private FormaPagamento formaPagamento = null;

    public FormaPagamento getFormaPagamento() {
        return formaPagamento;
    }

    public void setFormaPagamento(FormaPagamento formaPagamento) {
        this.formaPagamento = formaPagamento;
    }

    public void setFormaPagamentos(FormaPagamento formaPagamento) {
        this.formaPagamento = formaPagamento;

        jTextFieldFormaPagamento.setText(formaPagamento.getFormaPagamento());
    }
}
